<?php
include "inc-config.php";
include "inc-header.php";
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="8" height="6px" background="images/blizzMenu/blue/rb-tleft.gif"></td>
<td background="images/blizzMenu/blue/top.gif"></td>
<td background="images/blizzMenu/blue/rb-tright1.gif"></td>
</tr>
<tr>
<td background="images/blizzMenu/blue/rb-side.jpg" style="background-repeat:repeat-y; background-position:left"  bgcolor="#122031"></td>
<td  bgcolor="#122031">

<?php
$server = $ServerIP;		// Ascent Server Address
$port = $ServerPort;			// Ascent Server Port

$maps_a = array(
	0 => 'Azeroth',
	1 => 'Kalimdor',
	2 => 'UnderMine',
	13 => 'Test zone',
	17 => 'Kalidar',
	30 => 'Alterac Valley',
	33 => 'Shadowfang Keep',
	34 => 'The Stockade',
	35 => 'Stormwind Prison',
	36 => 'Deadmines',
	37 => 'Plains of Snow',
	43 => 'Wailing Caverns',
	44 => 'Monastery Interior',
	47 => 'Razorfen Kraul',
	48 => 'Blackfathom Deeps',
	70 => 'Uldaman',
	90 => 'Gnomeregan',
	109 => 'Sunken Temple',
	129 => 'Razorfen Downs',
	169 => 'Emerald Forest',
	189 => 'Scarlet Monastery',
	209 => 'Zul\'Farrak',
	229 => 'Blackrock Spire',
	230 => 'Blackrock Depths',
	249 => 'Onyxias Lair',
	269 => 'Caverns of Time',
	289 => 'Scholomance',
	309 => 'Zul\'Gurub',
	329 => 'Stratholme',
	349 => 'Maraudon',
	369 => 'Deeprun Tram',
	389 => 'Ragefire Chasm',
	409 => 'The Molten Core',
	429 => 'Dire Maul',
	449 => 'Alliance PVP Barracks',
	450 => 'Horde PVP Barracks',
	451 => 'Development Land',
	469 => 'Blackwing Lair',
	489 => 'Warsong Gulch',
	509 => 'Ruins of Ahn\'Qiraj',
	529 => 'Arathi Basin',
	530 => 'Burning Crusade Zones',
	531 => 'Temple of Ahn\'Qiraj',
	532 => 'Karazhan',
	533 => 'Naxxramas',
	534 => 'Hyjal Past',
	540 => 'Shattered Halls',
	542 => 'Blood Furnace',
	543 => 'Hellfire Ramparts',
	544 => 'Magtheridon\'s Lair',
	545 => 'The Steamvault',
	546 => 'The Black Temple',
	547 => 'The Slave Pens',
	548 => 'Coilfang Resevoir',
	550 => 'The Eye',
	552 => 'The Arcatraz',
	553 => 'The Botanica',
	554 => 'The Mechanar',
	555 => 'Shadow Labyrinth',
	556 => 'Sethekk Halls',
	557 => 'Mana-Tombs',
	558 => 'Auchenai Crypts',
	559 => 'Nagrand Arena',
	560 => 'Hillsbrad Past',
	562 => 'Blade\'s Edge Arena',
	564 => 'Black Temple',
	565 => 'Gruul\'s Lair',
	566 => 'Eye of the Storm',
	568 => 'Zul\'aman',
);

$zone = array(
	0 => array(
		array(700,10,1244,1873,'Undercity',1497),
		array(-840,-1330,-5050,-4560,'Ironforge',1537),
		array(1190,200,-9074,-8280,'Stormwind City',1519),
		array(-2170,-4400,-7348,-6006,'Badlands',3),
		array(-500,-4400,-4485,-2367,'Wetlands',11),
		array(2220,-2250,-15422,-11299,'Stranglethorn Vale',33),
		array(-1724,-3540,-9918,-8667,'Redridge Mountains',44),
		array(-2480,-4400,-6006,-4485,'Loch Modan',38),
		array(662,-1638,-11299,-9990,'Duskwood',10),
		array(-1638,-2344,-11299,-9918,'Deadwind Pass',41),
		array(834,-1724,-9990,-8526,'Elwynn Forest',12),
		array(-500,-3100,-8667,-7348,'Burning Steppes',46),
		array(-608,-2170,-7348,-6285,'Searing Gorge',51),
		array(2000,-2480,-6612,-4485,'Dun Morogh',1),
		array(-1575,-5425,-432,805,'The Hinterlands',47),
		array(3016,662,-11299,-9400,'Westfall',40),
		array(600,-1575,-1874,220,'Hillsbrad Foothills',267),
		array(-2725,-6056,805,3800,'Eastern Plaguelands',139),
		array(-850,-2725,805,3400,'Western Plaguelands',28),
		array(2200,600,-900,1525,'Silverpine Forest',130),
		array(2200,-850,1525,3400,'Tirisfal Glades',85),
		array(-2250,-3520,-12800,-10666,'Blasted Lands',4),
		array(-2344,-4516,-11070,-9600,'Swamp of Sorrows',8),
		array(-1575,-3900,-2367,-432,'Arathi Highlands',45),
		array(600,-1575,220,1525,'Alterac Mountains',36),
	),
	1 => array(
		array(2698,2030,9575,10267,'Darnassus',1657),
		array(326,-360,-1490,-910,'Thunder Bluff',1638),
		array(-3849,-4809,1387,2222,'Orgrimmar',1637),
		array(-1300,-3250,7142,8500,'Moonglade',493),
		array(2021,-400,-9000,-6016,'Silithus',1377),
		array(-2259,-7000,4150,8500,'Winterspring',618),
		array(-400,-2094,-8221,-6016,'Un\'Goro Crater',490),
		array(-590,-2259,3580,7142,'Felwood',361),
		array(-3787,-8000,1370,6000,'Azshara',16),
		array(-1900,-5500,-10475,-6825,'Tanaris',440),
		array(-2478,-5500,-5135,-2330,'Dustwallow Marsh',15),
		array(360,-1536,-3474,-412,'Mulgore',215),
		array(4000,-804,-6828,-2477,'Feralas',357),
		array(3500,360,-2477,372,'Desolace',405),
		array(-804,-5500,-6828,-4566,'Thousand Needles',400),
		array(-3758,-5500,-1300,1370,'Durotar',14),
		array(1000,-3787,1370,4150,'Ashenvale',331),
		array(2500,-1300,4150,8500,'Darkshore',148),
		array(3814,-1100,8600,11831,'Teldrassil',141),
		array(3500,-804,-412,3580,'Stonetalon Mountains',406),
		array(-804,-4200,-4566,1370,'The Barrens',17),
	),
	530 => array(
		array(6135.25,4829,-2344.78,-1473.95,'Shattrath City',3703),
		array(-6400.75,-7612.20,9346.93,10153.70,'Silvermoon City',3487),
		array(5483.33,-91.66,1739.58,5456.25,'Netherstorm',3523),
		array(7083.33,1683.33,-4600,-999.99,'Terokkar Forest',3519),
		array(10295.83,4770.83,-3641.66,41.66,'Nagrand',3518),
		array(-10075,-13337.49,-2933.33,-758.33,'Bloodmyst Isle',3525),
		array(8845.83,3420.83,791.66,4408.33,'Blades Edge Mountains',3522),
		array(4225,-1275,-5614.58,-1947.91,'Shadowmoon Valley',3520),
		array(-11066.36,-12123.13,-4314.37,-3609.68,'The Exodar',3557),
		array(9475,4447.91,-1416.66,1935.41,'Zangarmarsh',3521),
		array(5539.58,375,-1962.49,1481.25,'Hellfire Peninsula',3483),
		array(-10500,-14570.83,-5508.33,-2793.75,'Azuremyst Isle',3524),
		array(-5283.33,-8583.33,6066.66,8266.66,'Ghostlands',3433),
		array(-4487,-9412,7758,11041,'Eversong Woods',3430)
	),
);

$def = array(
	'character_race' => array(
		1 => 'Human',
		2 => 'Orc',
		3 => 'Dwarf',
		4 => 'Night&nbsp;Elf',
		5 => 'Undead',
		6 => 'Tauren',
		7 => 'Gnome',
		8 => 'Troll',
		9 => 'Goblin',
		10 => 'Blood&nbsp;Elf',
		11 => 'Draenei',
	),

	'character_class' => array(
		1 => 'Warrior',
		2 => 'Paladin',
		3 => 'Hunter',
		4 => 'Rogue',
		5 => 'Priest',
		7 => 'Shaman',
		8 => 'Mage',
		9 => 'Warlock',
		11 => 'Druid',
	),
);

function get_zone_name($mapid, $x, $y){
	global $maps_a, $zone;
	if (!empty($maps_a[$mapid]))
	{
		$zmap = $maps_a[$mapid];
		if (($mapid==0) or ($mapid==1) or ($mapid==530))
		{
			$i = 0;
			$c = count($zone[$mapid]);
			while ($i < $c)
			{
				if ($zone[$mapid][$i][2] < $x  AND $zone[$mapid][$i][3] > $x AND $zone[$mapid][$i][1] < $y  AND $zone[$mapid][$i][0] > $y)
					$zmap = $zone[$mapid][$i][4];
				$i++;
			}
		}
	}
	else
		$zmap = "Unknown zone";
	return $zmap;
} 

function test_realm(){
	global $server, $port;
	$s = @fsockopen($server, $port, $ERROR_NO, $ERROR_STR,(float)0.5);
	if($s){@fclose($s);return true;} else return false;
}

function make_players_array(){
	global $database_encoding, $pl_array, $char;
	$i = 0;
	$GetPlayers = "SELECT * FROM `characters` WHERE `online`='1' ORDER BY `name`";
	$GetPlayers2 = mysql_query($GetPlayers, $char) or die("Error #1: " . mysql_error());
	while($GetPlayers3 = mysql_fetch_array($GetPlayers2))
	{
		$char_data = ($GetPlayers3['level']);
		$char_gender = ($GetPlayers3['gender']);
		$char_name = ($GetPlayers3['name']);
		$res_pos = get_zone_name($GetPlayers3['mapId'], $GetPlayers3['positionX'], $GetPlayers3['positionY']);

		$pl_array[$i] = array($GetPlayers3['name'], $GetPlayers3['race'], $GetPlayers3['class'], $char_data, $res_pos, $char_gender, $GetPlayers3['pvprank'],);
		$i++;
	}
	return $i;
}

$onlineplayers = make_players_array();

if (!$sort = &$_GET['s'])
	$sort = 0;
if (!$flag = &$_GET['f'])
	$flag = 0;
if ($flag == 0)
{
	$flag = 1;
	$sort_type='<';
} 
else
{
	$flag=0;
	$sort_type='>';
}

$link=$_SERVER['PHP_SELF']."?f=".$flag."&s=";

if (!empty($pl_array)) 
{
	usort($pl_array, create_function('$a, $b', 'if ( $a['.$sort.'] == $b['.$sort.'] ) return 0; if ( $a['.$sort.'] '.$sort_type.' $b['.$sort.'] ) return -1; return 1;'));
}

$list = "";

$i = 0;

while ($i < $onlineplayers)
{
	$name = $pl_array[$i][0];
	$race = $pl_array[$i][1];
	$class = $pl_array[$i][2];
	$res_race = $def['character_race'][$race];
	$res_class = $def['character_class'][$class];
	$lvl = $pl_array[$i][3];
	$loc = $pl_array[$i][4];
	$gender = $pl_array[$i][5];
	$pvprank = $pl_array[$i][6];
	$list .= "
<tr>
	<td align='center'><img alt='$res_race' src='".$img_base."/pvpranks/rank$pvprank.gif' height='18' width='18'></td>
	<td>$name</td>
	<td align='center'>$lvl</td>
	<td align='center'><img alt='$res_race' src='".$img_base."/race/$race-$gender.gif' height='18' width='18'></td>
	<td align='center'><img alt='$res_class' src='".$img_base."class/$class.gif' height='18' width='18'></td>
	
	<td >$loc</td>
</tr>";
	$i++;
}

if (test_realm())
{
	$title.=(' ('.$onlineplayers.' '.$text["playerson"].')');
} else
{
	$title.=(' '.$text["off"]);
}
?>
<SCRIPT language=javascript>
<!--
var styleSheet;
var agt     = navigator.userAgent.toLowerCase();
var appVer  = navigator.appVersion.toLowerCase();
var verInt  = parseInt(appVer);
var ie      = (appVer.indexOf('msie') != -1);
var opera   = (agt.indexOf('opera') != -1);
var mozilla = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('opera')==-1)
&& (agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1)
&& (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
var ns4     = (mozilla && (verInt == 4));

if (ie && !opera) {
document.styleSheets["bnetstyle"].addRule ("input", "background-color: #040D1A");
document.styleSheets["bnetstyle"].addRule ("input", "border-style: solid");
document.styleSheets["bnetstyle"].addRule ("input", "border-width: 1px");
document.styleSheets["bnetstyle"].addRule ("input", "border-color: #7F7F7F");
document.styleSheets["bnetstyle"].addRule ("input", "color: #FFAC04");

document.styleSheets["bnetstyle"].addRule ("textarea", "background-color: #040D1A");
document.styleSheets["bnetstyle"].addRule ("textarea", "border-style: solid");
document.styleSheets["bnetstyle"].addRule ("textarea", "border-width: 1px");
document.styleSheets["bnetstyle"].addRule ("textarea", "border-color: #7F7F7F");
document.styleSheets["bnetstyle"].addRule ("textarea", "color: #FFAC04");

document.styleSheets["bnetstyle"].addRule ("textarea", "scrollbar-Base-Color: #012158");
document.styleSheets["bnetstyle"].addRule ("textarea", "scrollbar-Arrow-Color: #7F7F7F");
document.styleSheets["bnetstyle"].addRule ("textarea", "scrollbar-3dLight-Color: #7F7F7F");
document.styleSheets["bnetstyle"].addRule ("textarea", "scrollbar-DarkShadow-Color: black");
document.styleSheets["bnetstyle"].addRule ("textarea", "scrollbar-Highlight-Color: black");
document.styleSheets["bnetstyle"].addRule ("textarea", "scrollbar-Shadow-Color: #00B3FF");

document.styleSheets["bnetstyle"].addRule ("select", "background-color: #040D1A");
document.styleSheets["bnetstyle"].addRule ("select", "color: #FFAC04");

document.styleSheets["bnetstyle"].addRule ("select.gray", "background-color: #040D1A");
document.styleSheets["bnetstyle"].addRule ("select.gray", "color: #FFAC04");

document.styleSheets["bnetstyle"].addRule ("ul.thread", "margin-left: 22px;");
}
//-->
</SCRIPT>
<table cellpadding='0' cellspacing='4' align='center' style="color:#FFFFFF" width="680px">
	<tbody>
		<tr>
			<td align='left' nowrap='nowrap' width='18'></td>
			<td align='left' nowrap='nowrap' width='60'><a href="<?php print $link.'0">'.$text['char'][0] ?></a></td>
			<td align='center' nowrap='nowrap' width='40'><a href="<?php print $link.'3">'.$text['char'][3] ?></a></td>
			<td align='center' nowrap='nowrap' width='40'><a href="<?php print $link.'2">'.$text['char'][2] ?></a></td>
			<td align='center' nowrap='nowrap' width='40'><a href="<?php print $link.'1">'.$text['char'][1] ?></a></td>
			<td align='left' nowrap='nowrap' width='100'><a href="<?php print $link.'4">'.$text['char'][4] ?></a></td>
		</tr>
		<?php print $list ?></tbody>
	</tbody>
</table>

</td>
<td width="8"  background="images/blizzMenu/blue/rb-side.jpg" style="background-repeat:repeat-y; background-position:right" bgcolor="#122031"></td>
</tr>
<tr>
<td height="6px" background="images/blizzMenu/blue/rb-bleft.gif"></td>
<td  background="images/blizzMenu/blue/bot.gif"></td>
<td background="images/blizzMenu/blue/rb-bright1.gif"></td>
</tr>
</table>
<?php include "inc-footer.php"; ?>